package com.erp.generic.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/*
 * This class is responsible for the encryption of  raw password  using  MD5 Algorithm
 */
public class PasswordEncryptor 
{
	public String generateEncryptedPassword(String password)
	{
		String encryptedPassword =  password;
		byte[] defaultBytes1 = encryptedPassword.getBytes();
		try{
			MessageDigest algorithm = MessageDigest.getInstance("MD5");
			algorithm.reset();
			algorithm.update(defaultBytes1);
			byte messageDigest[] = algorithm.digest();

			StringBuffer hexString = new StringBuffer();
			for (int i=0;i<messageDigest.length;i++) {
				String word =  Integer.toHexString(0xFF & messageDigest[i]);
				if(word.length() == 1)
					word = "0"+word;
				hexString.append(word);
			}
			encryptedPassword = hexString+"";
		}
		catch(NoSuchAlgorithmException nsae){

		}
		return encryptedPassword;

	}

}
